package com.wk1un2.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wk1un2.entity.ArrposidProduct;
import com.wk1un2.service.ArrposidProductService;
import com.wk1un2.util.Result;
//推荐位置关联商品控制器
@Controller
public class ArrposidProductController {

	@Autowired
	ArrposidProductService service;

	@RequestMapping("/Backstage/getAllArrposidProduct")
	@ResponseBody
	public Object getAll(@RequestParam("page") int page, @RequestParam("limit") int limit,
			@RequestParam("a_id") String a_id,@RequestParam("p_id") String p_id) {

		if (a_id == null || a_id == "") {
			a_id = null;
		}
		if (p_id == null || p_id == "") {
			p_id = null;
		}
		List<ArrposidProduct> ls = service.getAll((page - 1) * limit, limit, a_id,p_id);
		Result res = new Result(0, "", service.count(), ls);
		return res;
	}

	//
	@RequestMapping("/Backstage/addArrposidProduct")
	@ResponseBody
	public Object add(@RequestParam Map<String, Object> map) {

		System.out.println(map.get("arrp_id"));
		int i = service.add(map);
		Result res = new Result(0, "", i, i);
		return res;
	}

//		޸
	@RequestMapping("/Backstage/updateArrposidProduct")
	@ResponseBody
	public Object update(@RequestParam Map<String, Object> map) {
		System.out.println(map.get("arrp_id"));
		int i = service.update(map);
		Result res = new Result(0, "", i, i);
		return res;
	}

//		ɾ
	@RequestMapping("/Backstage/deleteArrposidProduct")
	@ResponseBody
	public Object delete(@RequestParam("arrp_id") int arrp_id) {
		System.out.println(arrp_id);
		int i = service.delete(arrp_id);
		Result res = new Result(0, "", i, i);
		return res;
	}
}
